#ifndef NODO_H
#define NODO_H

#include<vector>
#include <sstream>

using std::vector;

//Se instancia a Arco para evitar la referencia cruzada.
template<class T>
class Arco;

#include "Arco.h"

template<class T>
class Nodo{
    
    private:
        int numero;
        vector< Arco<T> > arcos;
        unsigned color;
        T objeto;

    public:
        Nodo( int );
        Nodo( int , T& );
        ~Nodo();
        
        int getNum();
        void agregarArco( Nodo<T> & , int );
        void getArcos( vector< Arco<T> >& ) const;
        
        void setObjeto( T& );
        T& getObjeto();
        void setColor( unsigned col );
        unsigned getColor();
        
        string toString();
        static bool test();
        
};

template<typename T>
Nodo<T> :: Nodo( int num = 0 ){
    numero = num;
    color = 0;
}

template<class T>
Nodo<T> :: Nodo( int num , T& obj ){
    numero = num;
    objeto = obj;
    color = 0;
}

template<class T>
Nodo<T> :: ~Nodo(){
}

template<class T>
int Nodo<T> :: getNum(){
    return numero;
}

template<class T>
void Nodo<T> :: agregarArco( Nodo& nod , int longitud ){
    Arco<T> arc( nod , longitud );
    arcos.push_back( arc );
}

template<class T>
void Nodo<T> :: setObjeto( T& obj ){
    objeto = obj;
}

template<class T>
T& Nodo<T> :: getObjeto(){
    return objeto;
}

template<class T>
void Nodo<T> :: getArcos( vector< Arco<T> >& vec ) const{
    vec = arcos;
}

template<class T>
void Nodo<T> :: setColor( unsigned col ){
    color = col;
}

template<class T>
unsigned Nodo<T> :: getColor(){
    return color;
}

//toString
template<class T>
string Nodo<T> :: toString(){
    string nodoToString;
    
    ostringstream stream;

    stream << numero;

//    for(int i = 0; i < arcos.size(); i++)
  //      stream << arcos[i].toString();
    
    stream << objeto;
    
    nodoToString = stream.str();

    return nodoToString;
}

//test
template<class T>
bool Nodo<T> :: test(){
    Nodo<char> node1(1);
    Nodo<char> node2(2);
    
    node1.agregarArco(node2, 3);
    node2.agregarArco(node1, 2);
    
    cout << node1.getNum() << endl;
    cout << node2.getNum() << endl;
    
    vector< Arco<char> > arcos;
    
    node1.getArcos(arcos);

    cout << arcos[0].getNodo().getNum() << endl;
    cout << arcos[0].getLongitud() << endl;
    
    node2.getArcos(arcos);

    cout << arcos[0].getNodo().getNum() << endl;
    cout << arcos[0].getLongitud() << endl;
    
    return true;
}

#endif
